package web.login;


import org.apache.wicket.Component;
import org.apache.wicket.PageParameters;
import org.apache.wicket.markup.html.panel.EmptyPanel;
import org.apache.wicket.model.IModel;
import org.apache.wicket.model.Model;
import org.apache.wicket.spring.injection.annot.SpringBean;
import org.wicketstuff.annotation.mount.MountPath;
import org.wicketstuff.annotation.strategy.MountIndexedParam;
import service.PasswordResetService;
import web.cms.CmsBasePage;
import web.cms.CmsMainPage;

@MountIndexedParam
@MountPath(path = "passwordReset")
public final class PasswordResetPage extends CmsBasePage {

    @SpringBean
    PasswordResetService passwordService;

    public PasswordResetPage(PageParameters params) {
        String key = params.getString("0");
        if (key == null) {
            add(new ResetPasswordPanel("resetPasswordPanel", null));
        } else if (passwordService.checkPasswordResetKey(key)) {
            add(new ResetPasswordPanel("resetPasswordPanel", key));
        } else {
            getRequestCycle().setRedirect(true);
            setResponsePage(CmsMainPage.class);
        }
    }

    @Override
    public IModel getPageTitle() {
        return new Model("PasswordResetPage");
    }

    @Override
    public IModel getDescription() {
        return new Model("PasswordResetPage");
    }

    @Override
    public IModel getKeywords() {
        return new Model("PasswordResetPage");

    }


    @Override
    protected Component newRightPanel(String id) {
        return new EmptyPanel(id);
    }

    @Override
    protected Component newLeftPanel(String id) {
        return new EmptyPanel(id);
    }
}

